﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
    public class ChiTietPhieuMua_DAO
    {
        private static ChiTietPhieuMua_DAO m_instance = null;

        public static ChiTietPhieuMua_DAO Instance
        {
            get
            {
                if (m_instance == null)
                    m_instance = new ChiTietPhieuMua_DAO();
                return m_instance;
            }
        }

        /// <summary>
        /// THÊM CHI TIẾT PHIẾU MUA
        /// </summary>
        /// <param name="masp"></param>
        /// <param name="maphieumh"></param>
        /// <param name="soluong"></param>
        /// <param name="dongia"></param>
        /// <returns></returns>
        public bool ThemChiTietPhieuMua(string masp, string maphieumh, int soluong, long dongia)
        {
            try
            {
                SqlConnection cnn = SQLConnection.Instance.SqlConnection;
                SqlCommand cmd = new SqlCommand("ADD_CTPHIEUMUAHANG_MOI", cnn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@masp", SqlDbType.NVarChar, 10);
                cmd.Parameters["@masp"].Value = masp;
                cmd.Parameters.Add("@maphieumua", SqlDbType.NVarChar, 10);
                cmd.Parameters["@maphieumua"].Value = maphieumh;
                cmd.Parameters.Add("@soluong", SqlDbType.Int);
                cmd.Parameters["@soluong"].Value = soluong;
                cmd.Parameters.Add("@dongia", SqlDbType.Money);
                cmd.Parameters["@dongia"].Value = dongia;

                cmd.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
